import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, AlertController } from 'ionic-angular';
import { BusiProvider } from '../../providers/busi/busi';
import { NativeProvider } from '../../providers/native/native';

/**
 * Generated class for the RegisterPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-register',
  templateUrl: 'register.html',
})
export class RegisterPage {
  username:any;
  xm:any;
  age:any;
  address:any;
  email:any;
  sjhm:any;
  schools:any;
  schoolid:any;
  constructor(public navCtrl: NavController, public navParams: NavParams,public busi:BusiProvider,public native:NativeProvider,public alertCtrl:AlertController) {
    this.schools = this.navParams.get("schools");
    this.showPrompt();
  }

  showPrompt() {
    const prompt = this.alertCtrl.create({
      title: '平台协议',
      enableBackdropDismiss:false,
      message: "欢迎您与各校易平台经营者（详见定义条款）共同签署本《校易平台服务协议》并使用淘宝平台服务！<br>"+
      "1.您确认，在您开始注册程序使用校易平台服务前，您应当具备中华人民共和国法律规定的与您行为相适应的民事行为能力。若您不具备前述与您行为相适应的民事行为能力，则您及您的监护人应依照法律规定承担因此而导致的一切后果。<br>"+
      "2.在使用校易平台服务时，您应当按校易平台页面的提示准确完整地提供您的信息（包括您的姓名及电子邮件地址、联系电话、联系地址等），以便淘宝或其他用户与您联系。<br>"+
      "3.平台注册成功后默认密码为888888，请及时更改!",
      buttons: [
        {
          text: '同意',
          handler: data => {

          }
        },
        {
          text: '拒绝',
          handler: data => {
            this.navCtrl.pop();
          }
        }
      ]
    });
    prompt.present();
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad RegisterPage');
  }
  save(){
    let body = {
      username: this.username,
      xm: this.xm,
      age: this.age,
      address: this.address,
      email: this.email,
      sjhm: this.sjhm,
      schoolid:this.schoolid
    }
    this.busi.userAdd(body).subscribe(
      ()=>{
        this.native.showToast("注册成功!");
        this.navCtrl.pop();
      },
      error=>{

      }
    );
  }

}
